{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "10c8f0ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:python_a2a.client.network:Added agent 'EMI' from URL: http://localhost:4737\n",
      "INFO:python_a2a.client.network:Added agent 'Inflation' from URL: http://localhost:4747\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<python_a2a.client.network.AgentNetwork at 0x1924f3b9a90>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from python_a2a import AgentNetwork, A2AClient, AIAgentRouter\n",
    "\n",
    "# Create an agent network\n",
    "network = AgentNetwork(name=\"Economics Calculator\")\n",
    "\n",
    "# Add agents to the network\n",
    "network.add(\"EMI\", \"http://localhost:4737\")\n",
    "network.add(\"Inflation\", \"http://localhost:4747\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2327709f",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Create a router to intelligently direct queries to the best agent\n",
    "router = AIAgentRouter(\n",
    "    llm_client=A2AClient(\"http://localhost:5000/openai\"),  # LLM for making routing decisions\n",
    "    agent_network=network\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "e985cdb2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Routing to EMI with 1.00 confidence\n",
      "Response: The EMI for a loan of ₹200000 at 5.00% interest for 18 months is ₹11556.11\n"
     ]
    }
   ],
   "source": [
    "# Route a query to the appropriate agent\n",
    "query = \"Calculate EMI for ₹200000 at 5% interest over 18 months.\"\n",
    "agent_name, confidence = router.route_query(query)\n",
    "print(f\"Routing to {agent_name} with {confidence:.2f} confidence\")\n",
    "\n",
    "# Get the selected agent and ask the question\n",
    "agent = network.get_agent(agent_name)\n",
    "response = agent.ask(query)\n",
    "print(f\"Response: {response}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "5dfc357e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Routing to Inflation with 0.50 confidence\n",
      "Response: ₹1500000.00 adjusted for 9.00% inflation over 10 years is ₹3551045.51\n"
     ]
    }
   ],
   "source": [
    "# Route a query to the appropriate agent\n",
    "query = \"What is ₹1500000 worth if inflation is 9% for 10 years?\"\n",
    "agent_name, confidence = router.route_query(query)\n",
    "print(f\"Routing to {agent_name} with {confidence:.2f} confidence\")\n",
    "\n",
    "# Get the selected agent and ask the question\n",
    "agent = network.get_agent(agent_name)\n",
    "response = agent.ask(query)\n",
    "print(f\"Response: {response}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
